import { existsSync } from 'node:fs'
import { mkdir } from 'node:fs/promises'
import path from 'node:path'

/**
 * ensure file, if not exist, create it
 *
 * @param filepath
 */
export async function ensureFile(filepath: string): Promise<void> {
  const exist = existsSync(filepath)

  if (!exist) {
    await mkdir(path.dirname(filepath), { recursive: true })
  }
}
